﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Obra.SmugMug.Api;

namespace Obra.PowerShell.SmugMug
{
    internal class DriveCmdletServiceProvider :
        ICmdletService
    {
        public const string SMUGMUG = "http://www.smugmug.com";

        private readonly PathSegments pathSegments;
        private readonly ISmugMugClientService smugMugClient;
        private readonly IPathMappingService pathMappingService;

        /// <summary>
        /// c-tor
        /// </summary>
        public DriveCmdletServiceProvider(
            PathSegments pathSegments,
            ISmugMugClientService smugMugClient,
            PathMappingServiceProvider pathMappingService)
        {
            this.pathSegments = pathSegments;
            this.smugMugClient= smugMugClient;
            this.pathMappingService = pathMappingService;
        }

        #region ICmdletService Members

        /// <summary>
        /// User specified command line options.
        /// </summary>
        public DynamicParametersItem Options
        {
            get;
            set;
        }

        public string Name
        {
            get { return this.pathSegments.DriveName; }
        }

        public string Path
        {
            get { return this.pathSegments.Path; }
        }

        public void Clear()
        {
            throw new NotImplementedException();
        }

        public void Copy(string path)
        {
            throw new NotImplementedException();
        }

        public bool Exists()
        {
            return true;
        }

        public object Get()
        {
            throw new NotImplementedException();
        }

        public Uri GetUri()
        {
            string accountUri = String.Format(Resource.AccountUriTemplate,
                (this.smugMugClient.Session as LoginWithPasswordContract).User.DisplayName);

            return new Uri(accountUri);
        }

        /// <summary>
        /// Get the albums
        /// </summary>
        public DirectoryChild[] GetChildren()
        {
            var albums = this.smugMugClient.GetAlbums().Albums.Select(
                x => new Album(x, this.smugMugClient.Session, this.smugMugClient));

            return (from album in albums
                    orderby album.Name
                    select new DirectoryChild(
                        album.Name,
                        //SmugMug.Path.Combine(this.pathSegments.DriveName, album.Name),
                        System.IO.Path.Combine(this.pathSegments.DriveName, album.Name),
                        album)).ToArray();
        }

        /// <summary>
        /// True if this item is a container, such as an album.
        /// </summary>
        public bool IsContainer()
        {
            return true;
        }

        public void Move(string path)
        {
            throw new NotImplementedException();
        }

        public void New(string name, object value)
        {
            throw new NotImplementedException();
        }

        public void Remove()
        {
            throw new NotImplementedException();
        }

        public void Rename(string name)
        {
            throw new NotImplementedException();
        }

        public void Set(object value)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
